//
//  QYHomeVC.swift
//  QingYuJSQ
//
//  Created by 李东 on 2024/4/1.
//

import UIKit
import SnapKit

class QYHomeVC: QYBaseVC {
    
   
    @IBOutlet weak var settingBtn_top: NSLayoutConstraint!
    
    @IBOutlet weak var bgView: UIView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        configUI()
        NotificationCenter.default.addObserver(self, selector: #selector(showAd), name: .SDKInitFinish, object: nil)
    }
    
    @objc func showAd() {
        if AppProducts.shared.isPurchased {
            adHelper.removeBannerView()
        }else{
            if hasLoadAd {
                return
            }
            hasLoadAd = true
            adHelper.loadBanner(currentVC: self, isMainVC: false)
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if ADManager.initFinish {
            showAd()
        }
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        bgView.jw_corner(byRoundingCorners: [.topLeft, .topRight], radii: 25)
    }


    override var preferredStatusBarStyle: UIStatusBarStyle {
        .default
    }
    
    func configUI() {
        hideNavgaitionBar()
        settingBtn_top.constant = CGFloat.topPadding
    }
    
    @IBAction func settingHandle(_ sender: Any) {
        navigationController?.pushViewController(QYMeVC(), animated: true)
    }
    
    @IBAction func item1Handle(_ sender: Any) {
        if !AppProducts.shared.isPurchased {
            showSubVC()
            return
        }
        navigationController?.pushViewController(QYWebVC(url: AppConfig.H5_URL), animated: true)
    }
    
    @IBAction func item2Handle(_ sender: Any) {
        if !AppProducts.shared.isPurchased {
            showSubVC()
            return
        }
        navigationController?.pushViewController(QYTreeHoleVC(), animated: true)
    }
    
}
